package com.epoint.BookManager.action;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.epoint.BookManager.dao.BookInfoDao;
import com.epoint.BookManager.domain.BookInfo;
import com.epoint.BookManager.service.BookInfoService;


@WebServlet("/bookinfodetailaction")
public class BookInfoDetailAction extends HttpServlet
{
    private static final long serialVersionUID = 1L;
    BookInfoService bookInfoService = new BookInfoService();
    BookInfoDao bookInfoDao = new BookInfoDao();
    /**
     * @see HttpServlet#HttpServlet()
     */
    public BookInfoDetailAction() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String method = request.getParameter("method");
        String bookId = request.getParameter("id");
        if ("querybookinfobyid".equals(method)) {
            querybookinfobyid(bookId, response);
        }
    }


    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }

    
    private void querybookinfobyid(String bookId, HttpServletResponse response) throws IOException {
        BookInfo bookInfo = bookInfoDao.queryBookInfoByID(bookId);
        JSONObject json = new JSONObject();
        json.put("data", bookInfo);
        response.getWriter().write(JSON.toJSONString(json));
    }

}
